r = int(input('Введите четырёхзначное число:'))
d = []
x = 0
y = 0
if r // 1000 > 0 and r // 1000 < 10:
    r = str(r)
    for i in range(len(r)):
        d.append(r[i])
    for i in range(4):
        for j in range(4 - i):
            if i == 0:
                y = int(d[j])
            elif i == 1:
                y = int(d[j] + d[j + 1])
            elif i == 2:
                y = int(d[j] + d[j + 1] + d[j + 2])
            elif i == 3:
                y = int(d[j] + d[j + 1] + d[j + 2] + d[j + 3])
            r = y 
            if y == 1:
                r = 0
            elif y > 3:
                for k in range(2, y // 2 + 1):
                    if y % k == 0:
                        r = 0
                        break
            if x < r:
                x = r
    print(x)
else:
    print('0')

